//
//  KuaiFotterView.m
//  K8彩票
//
//  Created by zhoubo on 2017/6/9.
//  Copyright © 2017年 zhoubo. All rights reserved.
//

#import "KuaiFotterView.h"
#import "Config.h"

@interface KuaiFotterView ()

@property (nonatomic,strong) UIView* view;

@property (nonatomic,strong) NSMutableArray* btns;

@property (nonatomic,strong) UILabel* lbl;

@end

@implementation KuaiFotterView

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setup];
        
    }
    return self;
}

-(instancetype)initWithCoder:(NSCoder *)aDecoder
{
    if (self = [super initWithCoder:aDecoder]) {
        [self setup];
    }
    return self;
}


-(void)setup
{
    self.btns = [[NSMutableArray alloc]initWithCapacity:4];

    [self setbtnsandlines];
    

}



-(void)setbtnsandlines
{
    UILabel* lbl = [[UILabel alloc]init];
    self.lbl = lbl;
    lbl.frame = CGRectMake(0, 50, ScreenWidth() - 80, 30);
    lbl.text = NSLocalizedString(@"快速选号", @"快速选号");
    lbl.textAlignment = NSTextAlignmentCenter;
    [self addSubview:lbl];
    
    UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(lbl.frame)+10,ScreenWidth()-80 , 44)];
    view.backgroundColor = [UIColor whiteColor];
    self.view = view;
    self.view.layer.cornerRadius = 8;
    self.view.layer.borderWidth = 2.0f;
    self.view.layer.borderColor = [UIColor grayColor].CGColor;
    self.view.layer.masksToBounds = YES;
    
    [self addSubview:view ];
    
    NSArray* titles1 = @[@"大",@"小",@"单",@"双"];
    
    NSMutableArray* titles = [[NSMutableArray alloc]initWithCapacity:4];
    for (NSString* str  in titles1) {
        [titles addObject:NSLocalizedString(str, str )];
    }
    
    CGFloat width = (ScreenWidth()-80) / 4;
    
    for(int i = 0 ; i < 4; ++i)
    {
        UIButton* btn = [[UIButton alloc]initWithFrame:CGRectMake(width*i, 0, width, self.view.bounds.size.height)];
        [btn setTitle:titles[i] forState:UIControlStateNormal];
        
        [self.view addSubview:btn];
        
        btn.tag = i;
        [self.btns addObject:btn];
        [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(btnclick:) forControlEvents:UIControlEventTouchUpInside];
        
        UIView* lineview = [[UIView alloc]initWithFrame:CGRectMake(width*i, 0, 2, self.view.bounds.size.height)];
        lineview.backgroundColor = [UIColor grayColor];
        [self.view addSubview:lineview];
        
    }

}


-(void)btnclick:(UIButton*)btn
{
    [self.delegate chooseNumbers:btn.tag];
    
    
    for (UIButton* button in self.btns) {
        if (btn == button) {
            button.backgroundColor = [UIColor redColor];
            [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

        }
        else
        {
            button.backgroundColor = [UIColor whiteColor ];
            [button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        }
    }
    

}




//- (void)awakeFromNib {
//    [super awakeFromNib];
//    // Initialization code
//    
//    self.view.layer.cornerRadius = 5;
//    self.view.layer.borderWidth = 0.5f;
//    self.view.layer.borderColor = [UIColor grayColor].CGColor;
//    self.view.layer.masksToBounds = YES;
//    
//}

@end
